package com.liuyou.weather3;

import java.util.ArrayList;

/**
 * observable
 */
public class WeatherData implements Subject {
    private final ArrayList<WebsideObserver> websideObservers;
    private double temperature;
    private double pressure;
    private double humidity;

    public WeatherData() {
        websideObservers = new ArrayList<WebsideObserver>();
    }

    public void setData(double temperature, double pressure, double humidity) {
        this.temperature = temperature;
        this.pressure = pressure;
        this.humidity = humidity;
        notifyObserver();
    }

    @Override
    public void registerObserver(WebsideObserver websideObserver) {
        websideObservers.add(websideObserver);
    }

    @Override
    public void removeObserver(WebsideObserver websideObserver) {
        websideObservers.remove(websideObserver);
    }

    @Override
    public void notifyObserver() {
        for (WebsideObserver websideObserver : websideObservers) {
            websideObserver.update(temperature, pressure, humidity);
        }
    }
}
